from core.decorators.open_api import open_api
from views.Task.model import Task, TaskPlan, TaskGroup


class TaskService:
    @open_api(name="task.list")
    def task_list(self, employee_id, status, date=None, is_plan=None,is_group=False):
        return Task.get_employee_task(employee_id, status, date, is_plan,is_group)

    @open_api(name="task.get")
    def get_task_by_id(id_):
        return Task.super_get_json(id_)

    @open_api(name="add.task")
    def add_task(self, info):
        task_info = Task.create_data(info)
        # 拿到task_id之后创建计划表
        plan_info = {
            "task_id": task_info.get("id"),
            "start_time": f'{info.get("planStartTime")}:00',
            "end_time": f'{info.get("planEndTime")}:00',
            "employee_id": info.get("employee_id"),
            "end_date": "2999-12-31"  # TODO:先默认到永久时间
        }

        return TaskPlan.create_data(plan_info)

    @open_api(name="complete.task")
    def modify_task(self, id_):
        return Task.complete_task(id_)

    @open_api(name="delete.task")
    def delete_task(self, id_):
        return Task.remove_data(id_)


class TaskPlanService:
    @open_api(name="get.employee.plan.task")
    def get_employee_plan_tasks(self, employee_id, date):
        return TaskPlan.get_employee_plan_task(employee_id, date)


class TaskGroupService:
    @open_api(name="add.task.group")
    def add_task_group(self, employee_id, task_name, sequence=1):
        return TaskGroup.add_task_group(employee_id, task_name, sequence)

    @open_api(name="group.list")
    def task_groups(self, employee_id):
        return TaskGroup.get_groups_by_employee_id(employee_id)
